﻿@using Stamp_For_Africa_Version_2.Models
@using MvcPaging
@model PageOfList<Stamp>




<input type="hidden" id="StampId" name="StampId"/>
    
<script type="text/javascript">

  function showAddToMyCollectionDialog(sId) {
    $('#StampId').val(sId);
    
    $('#dialogAddToMyCollection').dialog({ width: 400 });
    return false;
  }


  function onAddStampToCollection() {

    var stampId = $('#StampId').val();
    var mintNh = $('#MNH').val();
    var mintH = $('#MH').val();
    var used = $('#Used').val();
    $.ajax(
			{
			  type: 'POST',
			  url: '/Stamps/AddStampToCollection',
			  data: { stampId: stampId, MintNH: mintNh, MintH: mintH, Used: used },
			  dataType: "json",

			  success: function (data, response) {
			    $("#dialogAddToMyCollection").dialog("close");

			  }
			});

    return false;
  }
</script>

@* Dialog *@
<div style="display: none;" id="dialogAddToMyCollection" title="Add to my collection">  
		<div style="position: relative;">
        <table>
					<tr>
						<td>
							@Html.Label("Mint - Never hinged:") 
						</td>
						<td>
							@Html.TextBox("MNH")<br/>
						</td>
					</tr>
					<tr>
						<td>
							@Html.Label("Mint - Hinged:") 
						</td>
						<td>
							@Html.TextBox("MH")<br/>
						</td>
					</tr>
					<tr>
						<td>
							@Html.Label("Used:") 
						</td>
						<td>
							@Html.TextBox("Used")<br/>
						</td>
					</tr>

				</table>
				<a href="" onclick="return onAddStampToCollection()">Add to my collection!</a>
    </div>    
</div>



<br />
<div align="center" class="roundedpanel">
  <table >
    @using (Html.BeginForm("Index", "Stamps", FormMethod.Post, new { id = "TheForm" }))
    {
    
      <tr style="text-align: center">
        <th>
        </th>
        <th valign="top" align="center" style="text-align: center; min-width: 150px">
          Name
        </th>
        <th valign="top" align="center" style="text-align: center; min-width: 150px">
          Country
        </th>
        <th valign="top" align="center" style="text-align: center">
          Issued between
        </th>
        <th valign="top" align="center" style="text-align: center">
          Category
        </th>
        <th valign="top" align="center" style="text-align: center">
          Sub-Category
        </th>
        <th valign="top" align="center">
          Issue Type
        </th>
        @{
      if (@User.Identity.IsAuthenticated)
      {
          <th>
            Mine
          </th>
					<th>
						Options
					</th>
      }
        }
      </tr>
    }
    @{
      var rowCount = 0;

      foreach (var item in Model)
      {

        var nstyle = "trrow1";
        if (rowCount % 2 == 0)
        {
          nstyle = "trrow2";
        }

      <tr class=@nstyle>
        <td>
          <fieldset style="background: white">
            <img alt ="" src='@Url.Action("ShowStamp", "Stamps", new { item.Id })' width="100" height="auto"/>
          </fieldset>
        </td>
        <td>
          @Html.ActionLink(item.DisplayName, "Details", new { id = item.Id })
        </td>
        <td>
          @Html.DisplayFor(modelItem => item.Country.Name)
        </td>
        <td style="text-align: center">
          @{
        String from = item.FromDate.Year.ToString();
        String to = item.ToDate.Year.ToString();
        String together = from + " - " + to;
			 
            @Html.Label(together);
																												 
          }
        </td>
        <td>
          @Html.DisplayFor(modelItem => item.Category.DisplayName)
        </td>
        <td>
          @Html.DisplayFor(modelItem => item.SubCategory)
        </td>
        <td>
          @{
                                 String issueType = "";
                                 switch (item.IssueType)
                                 {
                                   case IssueType.RegularIssue:
                                     issueType = "Regular Issue";
                                     break;

                                   case IssueType.Provisional:
                                     issueType = "Provisional";
                                     break;

                                   case IssueType.Commemorative:
                                     issueType = "Commemorative";
                                     break;
                                 }
										
            @Html.Label(issueType);
          }
        </td>
        @{
                                  if (User.Identity.IsAuthenticated)
                                  {
                                    if (item.InMyCollection)
                                    {
          <td>
            Yes
          </td>
          <td>
            Manage
          </td>
                                    }
                                    else
                                    {
 
          <td>
            No
          </td>
          <td>
            <a href="" onclick="return showAddToMyCollectionDialog('@item.Id')">Add</a>
          </td>

          
                                    }
                                  }
        }
      </tr>
                                  rowCount++;
      }
    }
  </table>
</div>
<div align="center">
  @foreach (PagerItem item in Html.PagerList(ViewData.Model))
  {
    if (item.IsSelected)
    {
    <a href='@item.Url' class="selectedPageNumber" >@item.Text</a>
    }
    else
    {
    <a href='@item.Url' class="pageNumbers">@item.Text</a>  
    }

  }
</div>
